<?php

namespace XWAM\Addon\POrgProduct\Controller;

/**
 * ProductCategoryController 类
 *
 * @since 1.0 <2015-11-16> SoChishun <14507247@qq.com> Added.
 */
class ProductCategoryController extends \XWAM\Controller\AppbaseController {

    /**
     * category_list操作
     * @since 1.0<2015-11-23> SoChishun Added.
     */
    public function category_list() {
        $this->assign('tree', AddonD('ProductCategory')->select_tree());
        $this->display_cpp();
    }

    public function get_category_tree_json() {
        $list = AddonD('ProductCategory')->select_json_tree();
        $this->ajaxReturn($list);
    }

    /**
     * 导出数据
     * @since 1.0 <2015-11-23> SoChishun Added.
     */
    public function category_export() {
        if (!$this->isSuperAdmin) {
            die('没有权限!');
        }
        $search_data = $this->get_category_search_data();
        $list = D('ProductCategory')->scope('export')->where($search_data['where'])->select();
        if (!$list) {
            $this->ajaxMsg(false, '找不到符合条件的记录!');
        }
        sofn_excel_export($list);
    }

    /**
     * 类别复制 
     * 
     * @param type $id
     * @since 1.0 <2015-11-23> SoChishun Added.
     */
    public function category_copy($id = 0) {
        if (!$id) {
            $this->ajaxMsg(false, '参数无效');
        }
        AddonD('ProductCategory')->copy_category($id);
        $this->ajaxMsg(true);
    }

    /**
     * category_edit操作
     * @param int $id 主键编号
     * @since 1.0<2015-11-23> SoChishun Added.
     */
    public function category_edit($id = 0) {
        if ($id) {
            $this->assign('data', AddonD('ProductCategory')->find($id));
        }
        $this->display();
    }

    /**
     * category_edit_save操作
     * @since 1.0<2015-5-23> SoChishun Added.
     */
    public function category_edit_save() {
        $result = AddonD('ProductCategory')->save_category();
        $this->dialogJump($result['status'],$result['info']);
    }

    /**
     * category_delete操作
     * @param string $id 主键编号
     * @since 1.0<2015-11-23> SoChishun Added.
     */
    public function category_delete($id = '') {
        $this->ajaxReturn(AddonD('ProductCategory')->delete_category($id));
    }
}
